package org.example.day;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2019/06/16 20:39
 */
public class LetCode1 {
    public static void main(String[] args) {
        int[] nums = {-1,-2,-3,-4,-5};
        int target = -8;
        int[] result = twoSum(nums,target);
        System.out.println(result.toString());
    }

    public static int[] twoSum(int[] nums, int target) {
        int[] index = new int[2];
        Map<Integer, Integer> map = new HashMap();
        for(int i=0;i<nums.length;i++){
            map.put(nums[i], i);
        }
        for(int i=0;i<nums.length;i++){
            Integer last = map.get(target-nums[i]);
            if(last != null && last > i){
                index[0] = i;
                index[1] = map.get(target-nums[i]);
                return index;
            }
        }
        return index;
    }
}
